package com.xiaoq.users.service;

import com.xiaoq.users.entity.UserPhoneEntity;
import com.xiaoq.users.repository.UserPhoneRepository;
import com.xiaoq.vo.PagingVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by chenjh on 2018/3/27.
 */
@Service
public class UserPhoneService {

    @Autowired
    private UserPhoneRepository userPhoneRepository;


    public boolean save(UserPhoneEntity userPhoneEntity){
        return userPhoneRepository.save(userPhoneEntity);
    }


    public boolean update(UserPhoneEntity userPhoneEntity){
        return userPhoneRepository.update(userPhoneEntity);
    }

    /**
     * @param province 省份(可为null)
     * @param city 城市(可为null)
     * @param areaCode 区域码(可为null)
     * @param pagingVo 分页参数
     * @return
     */
    public List<UserPhoneEntity> getUserPhoneList(String province, String city, String areaCode, PagingVo pagingVo) {
        return userPhoneRepository.getUserPhoneList(province, city, areaCode, pagingVo);
    }

    /**
     * @param province 省份(可为null)
     * @param city 城市(可为null)
     * @param areaCode 区域码(可为null)
     * @return
     */
    public long getUserPhoneListCount(String province, String city, String areaCode) {
        return userPhoneRepository.getUserPhoneListCount(province, city, areaCode);
    }

    /**
     *  根据电话号码或者userId 获取用户的归属地信息
     *  id 和 userId 不能全为null
     * @param userId userId
     * @param mobile 电话号码
     * @return
     */
    public UserPhoneEntity getUserPhoneByIdOrMobile(String userId, String mobile){
        return userPhoneRepository.getUserPhoneByIdOrMobile(userId, mobile);
    }

}
